package com.cskaoyan.util;

import com.cskaoyan.bean.Admin;
import com.cskaoyan.bean.MarketUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * 创建日期: 2022/05/09 21:50
 *
 * @author 孙豪骏
 */
public class GetLogedUser {
    //获得认证成功的用户信息；
    public static MarketUser getLogedUser() {
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()) {
            MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
            return marketUser;
        }
        return null;
    }

    public static Integer getUserId() {
        Subject subject = SecurityUtils.getSubject();

        Integer principal = 0;
        if(subject.isAuthenticated()){
            principal = (Integer) subject.getPrincipal();
        }
        return principal;
    }
}